﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Workflow.ComponentModel

Namespace System.Workflow.Activities
    <Designer(GetType(SequentialWorkflowDesigner), GetType(IRootDesigner)), ToolboxItem(False), Designer(GetType(SequentialWorkflowDesigner), GetType(IDesigner)), ToolboxBitmap(GetType(SequentialWorkflowActivity), "Resources.SequentialWorkflow.bmp"), SRCategory("Standard"), SRDisplayName("SequentialWorkflow")> _
    Public Class SequentialWorkflowActivity
        Inherits SequenceActivity
        ' Events
        <SRDescription("OnCompletedDescr"), SRCategory("Handlers"), MergableProperty(False)> _
        Public Custom Event Completed As EventHandler
            AddHandler(ByVal value As EventHandler)
                MyBase.AddHandler(SequentialWorkflowActivity.CompletedEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler)
                MyBase.RemoveHandler(SequentialWorkflowActivity.CompletedEvent, value)
            End RemoveHandler
        End Event
        <SRCategory("Handlers"), SRDescription("OnInitializedDescr"), MergableProperty(False)> _
        Public Custom Event Initialized As EventHandler
            AddHandler(ByVal value As EventHandler)
                MyBase.AddHandler(SequentialWorkflowActivity.InitializedEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler)
                MyBase.RemoveHandler(SequentialWorkflowActivity.InitializedEvent, value)
            End RemoveHandler
        End Event

        ' Methods
        Public Sub New()
        End Sub

        Public Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub

        Protected Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            MyBase.RaiseEvent(SequentialWorkflowActivity.InitializedEvent, Me, EventArgs.Empty)
            Return MyBase.Execute(executionContext)
        End Function

        Protected NotOverridable Overrides Sub OnSequenceComplete(ByVal executionContext As ActivityExecutionContext)
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            MyBase.RaiseEvent(SequentialWorkflowActivity.CompletedEvent, Me, EventArgs.Empty)
        End Sub


        ' Properties
        <DefaultValue(CStr(Nothing)), SRDescription("DynamicUpdateConditionDescr"), SRCategory("Conditions")> _
        Public Property DynamicUpdateCondition As ActivityCondition
            Get
                Return [TryCast](WorkflowChanges.GetCondition(Me),ActivityCondition)
            End Get
            Set(ByVal value As ActivityCondition)
                WorkflowChanges.SetCondition(Me, value)
            End Set
        End Property


        ' Fields
        Public Shared ReadOnly CompletedEvent As DependencyProperty = DependencyProperty.Register("Completed", GetType(EventHandler), GetType(SequentialWorkflowActivity))
        Public Shared ReadOnly InitializedEvent As DependencyProperty = DependencyProperty.Register("Initialized", GetType(EventHandler), GetType(SequentialWorkflowActivity))
    End Class
End Namespace

